﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Eje2_page1 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            ListItemCollection ciudades = new ListItemCollection();
            ddlCiudad.Items.Add(new ListItem("Gral Pacheco", "zona norte"));
            ddlCiudad.Items.Add(new ListItem("San Miguel", "zona oeste"));
            ddlCiudad.Items.Add(new ListItem("Boedo", "zona sur"));
            chkTemas.Items.Add("Ciencias");
            chkTemas.Items.Add("Literatura");
            chkTemas.Items.Add("Historia");
        }
    }

    protected void btnResumen_Click(object sender, EventArgs e)
    {
        if (valid())
        {
            string param = string.Empty;
            param = "?nom=" + txtNombre.Text;
            param = param + "&ape=" + txtApellido.Text;
            param = param + "&zona=" + ddlCiudad.SelectedValue;
            param = param + "&tema=";
            string temas = string.Empty;
            for (int i = 0; i < chkTemas.Items.Count; i++)
            {
                if (chkTemas.Items[i].Selected)
                {
                    temas = temas + chkTemas.Items[i].Text + "|";
                }
            }
            int position = temas.LastIndexOf('|');
            if (position != -1) temas = temas.Substring(0, position);
            param = param + temas;
            Response.Redirect("resume.aspx" + param);
        }
    }
    private bool valid()
    {
        bool valid = true;
        foreach (Control c in form1.Controls)
        {
            if (c is TextBox)
            {
                if (((TextBox)c).Text == "")
                {
                    ((TextBox)c).BorderColor = System.Drawing.Color.Red;
                    ((TextBox)c).BorderWidth = Unit.Pixel(1);
                    valid = false;
                }
                else
                {
                    ((TextBox)c).BorderColor = System.Drawing.Color.LightGray;
                    ((TextBox)c).BorderWidth = Unit.Pixel(1);
                }
            }
        }
        return valid;
    }
}